/**
 * Radio button class.
 * 
 * @author Andrey Anisimov <hercules@inbox.ru>
 * @see core.ui.CheckBox
 */

import core.ui.CheckBox;

class RadioButton extends CheckBox {
	
	/**
	 * @protected
	 * Creates and returns root element for radio button.
	 *
	 * @return HTMLElement
	 */
	this.createElement = function() {
		var div = document.createElement('div');
		
		// Create input
		var name = 'radio' + this.getParent().getId();
		
		try {
			 // HACK: IE unables to set name property dynamically:
			 // http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/name_2.asp
			this.input = document.createElement('<input type="radio" name="' + name + '">');
		} catch (ex) {
			this.input = document.createElement('input');
			this.input.type = 'radio';
			this.input.name = name;
		}
		
		this.input.id = this.getId() + '_input';
		
		// Adjust checkbox style to make it display almost
		// identical in IE, Mozilla and Opera.
		this.input.style.left = '0px';
		this.input.style.top = '0px';
		this.input.style.height = '100%';
		this.input.style.lineHeight = '100%';
		this.input.style.marginTop = this.input.style.marginBottom = 0;
		this.input.style.marginRight = '3px';
		this.input.style.styleFloat = this.input.style.cssFloat = 'left';
		div.appendChild(this.input);
		
		// Create label
		this.label = document.createElement('label');
		this.label.htmlFor = this.input.id;
		//core.ui.quirks.TextSelection.preventSelection(this.label);
		div.appendChild(this.label);
		
		return div;
	}

	/**
	 * @protected
	 * Returns input control type.
	 * 
	 * @return string
	 */
	this.getType = function() {
		return 'radio';
	}
}